home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / fixinc.winnt < prev    next >
Text File  |  1995-06-15  |  6KB  |  224 lines

  1. #! sh
  2. #
  3. #   fixinc.winnt  --  Install modified versions of Windows NT system include
  4. #   files.
  5. #
  6. #   Based on fixinc.sco script by Ian Lance Taylor (ian@airs.com)).
  7. #   Modifications by Douglas Rupp (drupp@cs.washington.edu)
  8. #
  9. # This file is part of GNU CC.
  10. # GNU CC is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2, or (at your option)
  13. # any later version.
  14. # GNU CC is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. # You should have received a copy of the GNU General Public License
  19. # along with GNU CC; see the file COPYING.  If not, write to
  20. # the Free Software Foundation, 59 Temple Place - Suite 330,
  21. # Boston, MA 02111-1307, USA.
  22. #
  23. #    This script munges the native include files provided with Windows NT
  24. #    3.5 SDK systems so as to provide a reasonable namespace when
  25. #    compiling with gcc.  The header files by default do not
  26. #    provide many essential definitions and declarations if
  27. #    __STDC__ is 1.  This script modifies the header files to check
  28. #    for __STRICT_ANSI__ being defined instead.  However the most 
  29. #    important modification is to change all occurrences of __stdcall
  30. #    and __cdecl to __attribute__((stdcall)) and __attribute__((cdecl)),
  31. #    respectively.  Once munged, the
  32. #    resulting new system include files are placed in a directory
  33. #    that GNU C will search *before* searching the /mstools/h
  34. #    directory.  This script should work properly for an /mstools/h
  35. #    directory dated 9/4/94 on the installation CDROM.
  36. #
  37. #    See README-fixinc for more information.
  38.  
  39. # Directory containing the original header files.
  40. INPUT=${2-${INPUT-/mstools/h}}
  41.  
  42. # Fail if no arg to specify a directory for the output.
  43. if [ x$1 = x ]
  44. then echo fixincludes: no output directory specified
  45. exit 1
  46. fi
  47.  
  48. # Directory in which to store the results.
  49. LIB=${1?"fixincludes: output directory not specified"}
  50.  
  51. # Make sure it exists.
  52. if [ ! -d $LIB ]; then
  53.   mkdir $LIB || exit 1
  54. fi
  55.  
  56. ORIG_DIR=`pwd`
  57.  
  58. # Make LIB absolute if it is relative.
  59. # Don't do this if not necessary, since may screw up automounters.
  60. case $LIB in
  61. /*)
  62.     ;;
  63. *)
  64.     cd $LIB; LIB=`${PWDCMD-pwd}`
  65.     ;;
  66. esac
  67.  
  68. echo 'Building fixincludes in ' ${LIB}
  69.  
  70. # Determine whether this filesystem has symbolic links.
  71. if ln -s X $LIB/ShouldNotExist 2>NUL; then
  72.   rm -f $LIB/ShouldNotExist
  73.   LINKS=true
  74. else
  75.   LINKS=false
  76. fi
  77.  
  78. echo 'Making directories:'
  79. cd ${INPUT}
  80. if $LINKS; then
  81.   files=`ls -LR | sed -n s/:$//p`
  82. else
  83.   files=`find . -type d -print | sed '/^.$/d'`
  84. fi
  85. for file in $files; do
  86.   rm -rf $LIB/$file
  87.   if [ ! -d $LIB/$file ]
  88.   then mkdir $LIB/$file
  89.   fi
  90. done
  91.  
  92. # treetops gets an alternating list
  93. # of old directories to copy
  94. # and the new directories to copy to.
  95. treetops="${INPUT} ${LIB}"
  96.  
  97. set - $treetops
  98. while [ $# != 0 ]; do
  99.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  100.   echo "Finding header files in $1:"
  101.   cd ${INPUT}
  102.   cd $1
  103.   files=`find . -name '*.[hH]' -type f -print`
  104.   echo 'Checking header files:'
  105.   for file in $files; do
  106.     echo $file
  107.     if egrep "!__STDC__" $file >NUL; then
  108.       if [ -r $file ]; then
  109.     cp $file $2/$file >NUL 2>&1 || echo "Can't copy $file"
  110.     chmod +w,a+r $2/$file
  111.  
  112. # The following have been removed from the sed command below
  113. # because it is more useful to leave these things in.
  114. # The only reason to remove them was for -pedantic,
  115. # which isn't much of a reason. -- rms.
  116. #      /^[     ]*#[     ]*ident/d
  117.  
  118.     sed -e '
  119.       s/!__STDC__/!defined (__STRICT_ANSI__)/g
  120.     ' $2/$file > $2/$file.sed
  121.     mv $2/$file.sed $2/$file
  122.     if cmp $file $2/$file >NUL 2>&1; then
  123.        rm $2/$file
  124.     else
  125.        echo Fixed $file
  126.     fi
  127.       fi
  128.     fi
  129.   done
  130.   shift; shift
  131. done
  132.  
  133. # Fix first broken decl of getcwd present on some svr4 systems.
  134.  
  135. file=direct.h
  136. base=`basename $file`
  137. if [ -r ${LIB}/$file ]; then
  138.   file_to_fix=${LIB}/$file
  139. else
  140.   if [ -r ${INPUT}/$file ]; then
  141.     file_to_fix=${INPUT}/$file
  142.   else
  143.     file_to_fix=""
  144.   fi
  145. fi
  146. if [ \! -z "$file_to_fix" ]; then
  147.   echo Checking $file_to_fix
  148.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
  149.   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
  150.     true
  151.   else
  152.     echo Fixed $file_to_fix
  153.     rm -f ${LIB}/$file
  154.     cp /tmp/$base ${LIB}/$file
  155.     chmod a+r ${LIB}/$file
  156.   fi
  157.   rm -f /tmp/$base
  158. fi
  159.  
  160. file=rpcndr.h
  161. base=`basename $file`
  162. if [ -r ${LIB}/$file ]; then
  163.   file_to_fix=${LIB}/$file
  164. else
  165.   if [ -r ${INPUT}/$file ]; then
  166.     file_to_fix=${INPUT}/$file
  167.   else
  168.     file_to_fix=""
  169.   fi
  170. fi
  171. if [ \! -z "$file_to_fix" ]; then
  172.   echo Checking $file_to_fix
  173.   sed -e 's/Format\[\]/Format\[1\]/' $file_to_fix > /tmp/$base
  174.   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
  175.     true
  176.   else
  177.     echo Fixed $file_to_fix
  178.     rm -f ${LIB}/$file
  179.     cp /tmp/$base ${LIB}/$file
  180.     chmod a+r ${LIB}/$file
  181.   fi
  182.   rm -f /tmp/$base
  183. fi
  184.  
  185. file=winnt.h
  186. base=`basename $file`
  187. if [ -r ${LIB}/$file ]; then
  188.   file_to_fix=${LIB}/$file
  189. else
  190.   if [ -r ${INPUT}/$file ]; then
  191.     file_to_fix=${INPUT}/$file
  192.   else
  193.     file_to_fix=""
  194.   fi
  195. fi
  196. if [ \! -z "$file_to_fix" ]; then
  197.   echo Checking $file_to_fix
  198.   sed -e '
  199.     s/^#if !defined (__cplusplus)/#if 0/
  200.     s/^#define DECLSPEC_IMPORT __declspec(dllimport)/#define DECLSPEC_IMPORT/
  201.   ' $file_to_fix > /tmp/$base
  202.   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
  203.     true
  204.   else
  205.     echo Fixed $file_to_fix
  206.     rm -f ${LIB}/$file
  207.     cp /tmp/$base ${LIB}/$file
  208.     chmod a+r ${LIB}/$file
  209.   fi
  210.   rm -f /tmp/$base
  211. fi
  212.  
  213. echo 'Removing unneeded directories:'
  214. cd $LIB
  215. files=`find . -type d -print | sort -r`
  216. for file in $files; do
  217.   rmdir $LIB/$file > NUL 2>&1
  218. done
  219.  
  220. exit 0
  221.